package cn.tedu.weibo1.Controller;

import cn.tedu.weibo1.mapper.LoginMapper;
import cn.tedu.weibo1.pojo.dto.UserLoginDTO;
import cn.tedu.weibo1.pojo.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class LoginController {
    @Autowired(required = false)
    LoginMapper mapper;
    @RequestMapping("/login/select")
    public int select(@RequestBody UserLoginDTO userLoginDTO, HttpSession session){
        UserVO userVO=mapper.select(userLoginDTO.getUsername());
        if(userVO!=null){
            if(userVO.getPassword().equals(userLoginDTO.getPassword())){
                session.setAttribute("user",userVO);
                return 1;
            }
            return 2 ;
        }
        return 3;
    }
    @RequestMapping("/selectUser")
    public UserVO selectUser(HttpSession session){
        return (UserVO)session.getAttribute("user");
    }
    @RequestMapping("/romeUser")
    public void romeUser(HttpSession session){
        session.removeAttribute("user");
    }
}
